/*
 * @Author: your name
 * @Date: 2021-09-14 18:53:01
 * @LastEditTime: 2021-11-09 11:26:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \jingfeng-web\src\utils\hasPermission.js
 */
/*
 * @Author: your name
 * @Date: 2021-08-31 14:13:13
 * @LastEditTime: 2021-11-05 14:40:50
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \jinfeng_up\src\utils\hasPermission.js
 */
const hasPermission = {
    install(Vue) {
        Vue.directive('has', {
            inserted: (el, binding) => {
                filterGlobalPermission(el, binding)
            }
        })
    }
}
/**
 * 全局权限控制
 */
export const filterGlobalPermission = (el, binding) => {
    const permissionList = []
    const authList = sessionStorage.BUTTONLIST && JSON.parse(sessionStorage.getItem('BUTTONLIST'))
    for (const auth of authList) {
        permissionList.push(auth)
    }

    if (!permissionList.length) {
        console.log(el)
        console.log(el.parentNode)
        if (el.parentNode) {
            el.parentNode.removeChild(el)
        }

        return
    }
    const permissions = []
    for (const item of permissionList) {
        permissions.push(item.permCode)
    }
    if (!permissions.includes(binding.value)) {
        if (el.parentNode) {
            el.parentNode.removeChild(el)
        }
    }
}
export default hasPermission
